﻿using ShareCode.Entity.User;
using Infrastructure.Attributes.Ioc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dao.User
{
    /// <summary>
    /// by zhouxin
    ///</summary>
    [Component]
    public class UserApiDao : BaseTreeDao<UserApiEntity>
    {
        public async Task<UserApiEntity> InsertPath(string path, string desc, long pid, long rootid)
        {
            var aa = await this.FirstAsync(t => t.Title == path);

            if (aa != default)
            {
                aa.Title = path;
                aa.Remarks = desc;
                this.Update(aa);
            }

            var re = new UserApiEntity
            {
                Title = path,
                Remarks = desc,
                TreeParentId = pid,
                TreeRootId = rootid
            };

            var bb = await this.TreeInsertSon(re);

            return re;

        }
        public async Task<UserApiEntity> InsertAPI(string path, string desc, string code, long pid, long rootid)
        {
            var aa = await this.FirstAsync(t => t.Title == path);

            if (aa != default)
            {
                aa.Title = path;
                aa.Remarks = desc;
                aa.TreeParentId = pid;
                aa.TreeRootId = rootid;
                aa.TheCode = code;

                this.Update(aa);
            }
            var re = new UserApiEntity
            {
                Title = path,
                Remarks = desc,
                TreeParentId = pid,
                TreeRootId = rootid,
                TheCode = code
        };

            var bb = await this.TreeInsertSon(re);

            return re;

        }
    }
}
